﻿package org.hsl.avm2.translation.mouse;
import flash.events.MouseEvent;
import org.hsl.haxe.translation.ITranslator;
import org.hsl.haxe.translation.NativeEvent;
/**
 * A translator that translates mouse events to modifier keys states. The modifier keys states are the states of the
 * modifier keys (the Control, Alt and Shift keys) at the moment the mouse events were dispatched.
 */
// Ideally, the following line would be:
// class ModifierKeysStateTranslator implements ITranslator<ModifierKeysState> {
// However, that doesn't work targetingAVM2.
class ModifierKeysStateTranslator<D> implements ITranslator<D> {
	/**
	 * Creates a new modifier keys state translator.
	 */
	public function new():Void {
	}
	public function translate(nativeEvent:NativeEvent):D {
		var mouseEvent:MouseEvent;
		try {
			mouseEvent = cast(nativeEvent, MouseEvent);
		} catch (error:Dynamic) {
			throw "The nativeEvent argument must be a MouseEvent.";
		}
		return untyped new ModifierKeysState(mouseEvent.altKey, mouseEvent.ctrlKey, mouseEvent.shiftKey);
	}
}